package com.example.gbtdemo;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import org.apache.ibatis.annotations.Mapper;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName mybatisPlusGenerator
 * @Author 刘泽
 * @Mail liuze713@hotmail.com
 * @Date 2022/9/21 12:33
 * @Version 1.0
 */
public class MybatisPlusGenerator {
    private static final String url = "jdbc:mysql://43.138.126.232:3306/gbt_demo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai";
    private static final String username = "root";
    private static final String password = "Gbtxspp7449";
    private static final String filePath = "/Users/liuze/Desktop/generator";

    public static void main(String[] args) {
        List<String> tables = new ArrayList<>();
        tables.add("app_user");

        FastAutoGenerator.create(url, username, password)
                .globalConfig(builder -> {
                    builder.author("刘泽")
                            .outputDir(filePath)
                            .enableSwagger() // 开启 swagger 模式
                            .commentDate("yyyy-MM-dd HH:mm:ss");
                })
                .packageConfig(builder -> {
                    builder.parent("com.example.gbtdemo")
                            .entity("entity")
                            .service("service")
                            .serviceImpl("service.impl")
                            .controller("controller")
                            .mapper("mapper")
                            .xml("mapperXml");
                })
                .strategyConfig(builder -> {
                    builder.addInclude(tables)
                            .addTablePrefix("admin_")
                            .serviceBuilder()
                            .formatServiceFileName("%sService")
                            .formatServiceImplFileName("%sServiceImpl")
                            .entityBuilder()
                            .enableLombok()
                            .enableTableFieldAnnotation()
                            .controllerBuilder()
                            .formatFileName("%sController")
                            .enableRestStyle()
                            .mapperBuilder()
                            .enableBaseResultMap()
                            .superClass(BaseMapper.class)
                            .formatMapperFileName("%sMapper")
//                            .enableMapperAnnotation()
                            .mapperAnnotation(Mapper.class)
                            .formatXmlFileName("%sMapper");
                }).execute();
    }

}
